/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.converter;

import br.com.foxline.model.Customer;
import br.com.foxline.service.CustomerService;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author luciano
 */
@FacesConverter(value="customerconverter")
public class CustomerConverter implements Converter{

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
       Customer c = new Customer();
       if(!value.equals("null")){
           c.setId(Long.valueOf(value));
       } 
        return c;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Customer c = (Customer) value;
        return String.valueOf(c.getId());
    }
    
}
